﻿using System;
using System.Collections;
using System.Windows.Controls;

namespace Charts.Converters
{
	public class YValueAxisConverter : MultiValueConverterBase<YValueAxisConverter>
	{
		public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			//FIXME нельзя использовать свойства внутри мультиконвертора
			ContentPresenter t = (ContentPresenter)values[0];
			
			double ch = (double)values[1];

			IList list = (IList)values[2];
			double n = (double)list.Count;
			double i = (double)list.IndexOf(t.Content);
			
			double k = 1 - i / (n - 1);
			double result = -0.5 * t.ActualHeight + k * ch;
			return result;
		}
	}
}
